package com.example.animalcase;

import android.content.Context;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;


public class HomeFragment extends Fragment {
    private Button startButton,stopButton;
    private TextView radioText,webText;

    private MediaPlayer mMediaPlayer;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v= inflater.inflate(R.layout.fragment_home, container, false);

        startButton=(Button) v.findViewById(R.id.start_button);
        stopButton=(Button) v.findViewById(R.id.stop_button);
        radioText=(TextView)v.findViewById(R.id.radio_text);
        webText=(TextView)v.findViewById(R.id.web_text);

        startButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMediaPlayer=mMediaPlayer.create(getActivity(),R.raw.healer);
                mMediaPlayer.start();
            }
        });
        stopButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mMediaPlayer.stop();
            }
        });

        webText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Uri uriBrower=Uri.parse("https://www.baidu.com");
                startActivity(new Intent(Intent.ACTION_VIEW,uriBrower));
            }
        });

        radioText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                startActivity(new Intent(getActivity(),Mp4Activity.class));
            }
        });

        return v;
    }

}
